/**
 * 
 */
package dormouse.xml;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
 * @author mfortner
 *
 */
public class XMLUtil {
	
	/**
	 * This method gets the value of a subnode
	 * @param node
	 * @param subnodeName
	 * @return
	 */
	public static String getSubNodeValue(Element node, String subnodeName){
		String val = null;
		NodeList nl = node.getElementsByTagName(subnodeName);
		if (nl != null && nl.getLength() > 0){
			val = nl.item(0).getTextContent();
		}
		
		return val;
		
	}
	
	public static Element getSubNode(Element node, String subnodeName){
		Element val = null;
		NodeList nl = node.getElementsByTagName(subnodeName);
		if (nl != null && nl.getLength() > 0){
			val = (Element)nl.item(0);
		}
		
		return val;		
	}
	
	
	public static Element getSubNodeNS(Element node, String subnodeName, String namespaceURI){
		Element val = null;
		NodeList nl = node.getElementsByTagNameNS(namespaceURI, subnodeName);
		if (nl != null && nl.getLength() > 0){
			val = (Element)nl.item(0);
		}
		
		return val;
		
	}
	
	
	public static String getSubNodeValueNS(Element node, String subnodeName, String namespaceURI){
		String val = null;
		NodeList nl = node.getElementsByTagNameNS(namespaceURI, subnodeName);
		if (nl != null && nl.getLength() > 0){
			val = nl.item(0).getTextContent();
		}
		
		return val;
		
	}
	

}
